home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / wnos5src.zip / ARPDUMP.C < prev    next >
Text File  |  1993-07-27  |  2KB  |  68 lines

  1. #include "global.h"
  2. #include "mbuf.h"
  3. #include "arp.h"
  4. #include "netuser.h"
  5. #include "trace.h"
  6.  
  7. void
  8. arp_dump(FILE *fp,struct mbuf **bpp)
  9. {
  10.     struct arp arp;
  11.     struct arp_type *at;
  12.     char is_ip = 0, op = 0, tmp[30];
  13.  
  14.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  15.         return;
  16.  
  17.     if(ntoharp(&arp,bpp) == -1){
  18.         trprintf(fp,"ARP: bad packet\n");
  19.         return;
  20.     }
  21.  
  22.     at = (arp.hardware < NHWTYPES) ? &Arp_type[arp.hardware] : NULLATYPE;
  23.  
  24.     /* Print hardware type in Ascii if known, numerically if not */
  25.     trprintf(fp,"ARP: len %d hwtype %s",
  26.         len_p(*bpp),Arptypes[arp.hardware]);
  27.  
  28.     /* Print hardware length only if unknown type, or if it doesn't match
  29.      * the length in the known types table
  30.      */
  31.     if(at == NULLATYPE || arp.hwalen != at->hwalen)
  32.         trprintf(fp," hwlen %u",arp.hwalen);
  33.  
  34.     /* Check for most common case -- upper level protocol is IP */
  35.     if(at != NULLATYPE && arp.protocol == at->iptype){
  36.         trprintf(fp," prot IP op ");
  37.         is_ip = 1;
  38.     } else {
  39.         trprintf(fp," prot 0x%x prlen %u op ",arp.protocol,arp.pralen);
  40.     }
  41.  
  42.     if(arp.opcode == RARP_REQUEST || arp.opcode == RARP_REPLY)
  43.         trprintf(fp,"REVERSE ");
  44.  
  45.     switch(arp.opcode){
  46.     case ARP_REQUEST:
  47.         trprintf(fp,"REQUEST\n");
  48.         break;
  49.     case ARP_REPLY:
  50.         trprintf(fp,"REPLY\n");
  51.         op = 1;
  52.         break;
  53.     default:
  54.         trprintf(fp,"%u\n",arp.opcode);
  55.         break;
  56.     }
  57.     trprintf(fp,"     HW: sender %s",at->format(tmp,arp.shwaddr));
  58.     if(op) {
  59.         trprintf(fp," target %s",at->format(tmp,arp.thwaddr));
  60.     }
  61.     trprintf(fp,"\n");
  62.  
  63.     if(is_ip) {
  64.         trprintf(fp,"     IP: sender %s",inet_ntoa(arp.sprotaddr));
  65.         trprintf(fp," target %s\n",inet_ntoa(arp.tprotaddr));
  66.     }
  67. }
  68.